<template>
	<view class="login">
		<dwu-navbar bgColor="transparent" title=" "></dwu-navbar>
		<image class="login-bg" src="@/static/login/bg.png" mode=""></image>
		<view class="title">
			Hi，欢迎使用电无U
		</view>
		<image class="icon" src="@/static/login/icon.png" mode=""></image>
		<view class="login-btn">
			<button v-if="checked" class="getPhoneNumber" open-type="getPhoneNumber"
				@getphonenumber="getphonenumber">手机号快捷登录</button>
			<button v-else class="getPhoneNumber" @click="verification">手机号快捷登录</button>
			<view class="agreement">
				<view class="agreement-radio" @click="radioChange">
					<!-- <radio value="" :checked="checked" @click="radioChange" /> -->
					<image v-if="!checked" src="@/static/login/select.png" mode=""></image>
					<image v-else src="@/static/login/selected.png" mode=""></image>
					<text>我已阅读并同意<text @click="onJump('/subpackage/agreement/agreement?type=user')">用户协议</text>和<text style="margin-right: 0;" @click="onJump('/subpackage/agreement/agreement?type=privacy')">隐私政策</text>。</text>
				</view>
				<view class="tips" v-if="tipsShow">
					<image src="@/static/login/tips_bg.png" mode=""></image>
					<text>请先阅读并勾选用户协议</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false,
				tipsShow: false
			};
		},
		methods: {
			verification() {
				this.tipsShow = true
			},
			getphonenumber(e) {
				uni.login({
					success: (res) => {
						console.log(res);
						if (!e.detail.code) {
							uni.showToast({
								icon: 'none',
								title: '获取手机号失败'
							})
							return
						}
						this.request.http('/user/getOpenid', 'post', {code: res.code}).then(res => {
							let data = res.data
							if (data.code == 1) {
								this.request.http('/user/accreditLogin', 'post', {code: e.detail.code,openid: data.data.openid}).then(res => {
									let data = res.data
									if (data.code == 1) {
										uni.setStorageSync('dwu_userinfo', data.data.userinfo)
										uni.setStorageSync('dwu_token', data.data.userinfo.token)
										uni.reLaunch({
											url: '/pages/index/index'
										})
									}
								})
							}
						})
					}
				})
				console.log(e);
			},
			radioChange(e) {
				this.checked = !this.checked
				this.tipsShow = false
			},
			onJump(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.login {
		background: transparent;

		.login-bg {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			z-index: -1;
		}

		.title {
			margin-top: 155rpx;
			margin-left: 86rpx;
			width: 264rpx;
			height: 112rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 40rpx;
			color: #313131;
			line-height: 56rpx;
		}

		.icon {
			position: fixed;
			top: 160rpx;
			right: 75rpx;
			width: 248rpx;
			height: 344rpx;
		}

		.login-btn {
			position: fixed;
			bottom: 180rpx;
			width: 100%;
		}

		.getPhoneNumber {
			width: 600rpx;
			height: 106rpx;
			background: #3D3D3D;
			border-radius: 38rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 31rpx;
			color: #B0DD67;
			line-height: 106rpx;
		}

		.agreement {
			position: relative;
			width: 430rpx;
			margin: 35rpx auto 0;

			.agreement-radio {
				display: flex;
				align-items: center;

				image {
					margin-top: 2rpx;
					margin-right: 10rpx;
					width: 25rpx;
					height: 25rpx;
				}

				// radio {
				// 	transform: scale(.5);
				// 	margin-right: -10rpx;
				// }

				text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 21rpx;
					color: #999999;

					text {
						margin: 0 10rpx;
						color: #555555;
					}
				}
			}

			.tips {
				position: absolute;
				width: 242rpx;
				height: 36rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 300;
				font-size: 19rpx;
				color: #9C9C9C;
				line-height: 36rpx;
				text-align: center;

				image {
					position: absolute;
					top: 0;
					left: 0;
					width: 242rpx;
					height: 36rpx;
				}

				text {
					position: relative;
					z-index: 9;
				}
			}
		}
	}
</style>